#!/usr/bin/env python
#
# This file contains functions aimed at performing POS (parts of speech) tagging.
#

# Imports
import nltk


# Function to return the parts of speech tags for a given sentence
#
# Inputs:
#    - sentence
#
# Outputs:
#    - list of tuples [('And', 'CC'), ('now', 'RB')]
def getPOSTagsForSentence(sentence):
    
    # Tokenize the sentence into words
    words_tokenized = nltk.word_tokenize(sentence)
    
    # POS tag the list of words
    pos_tags = nltk.pos_tag(words_tokenized)
    
    return pos_tags


# Function to get the verbs from a sentence
def getVerbsFromSentence(sentence):
    
    verbs = []
    
    # Tokenize the sentence into words
    words_tokenized = nltk.word_tokenize(sentence)
    
    # POS tag the list of words
    pos_tags = nltk.pos_tag(words_tokenized)
    
    # Loop over the tags
    for (word, tag) in pos_tags:
        
        # Check if the tag starts with 'V'
        if tag[0] == 'V' :
            # Append the word to the list of verbs
            verbs.append(word)
    
    return verbs


# Function to print the frequency distribution of tags for the given sentence
#
# Inputs:
#    - sentence
#
# Outputs:
#    - tabulated output of the term frequency
def printFreqDist(sentence):
    
    # Tokenize the sentence into words
    words_tokenized = nltk.word_tokenize(sentence)
    
    # POS tag the list of words
    pos_tags = nltk.pos_tag(words_tokenized)
    
    # Get the frequency distribution
    fd = nltk.FreqDist(pos_tags)
    
    fd.tabulate()

if __name__ == '__main__':

	input = raw_input("Enter the test sentence: ")
	tags = getPOSTagsForSentence(input)
	print "Here is the output from the POS tagging:"
	for tag in tags:
		print "Word: %s, Tag: %s" % (tag[0], tag[1])
